package com.share.device.controller;


import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.CabinetType;
import com.share.device.service.ICabinetTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 柜机类型表 前端控制器
 * </p>
 *
 * @author pww
 * @since 2025-03-24
 */
@RestController
@Tag(name = "CabinetTypeController", description = "柜机类型表")
@RequestMapping("/cabinetType")
public class CabinetTypeController extends BaseController {
    @Autowired
    private ICabinetTypeService cabinetTypeService;


    /**
     * 查询所有数据
     *
     * @return
     */
    @Operation(summary = "查询所有数据")
    @GetMapping("/getCabinetTypeList")
    public AjaxResult getCabinetTypeList() {
        return success(cabinetTypeService.list());
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @Operation(summary = "删除")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable List<Long> ids) {
        boolean is_success = cabinetTypeService.removeBatchByIds(ids);
        AjaxResult ajaxResult = toAjax(is_success);
        return ajaxResult;
    }

    /**
     * 修改
     *
     * @param cabinetType
     * @return
     */
    @Operation(summary = "更新")
    @PutMapping
    public AjaxResult update(@RequestBody CabinetType cabinetType) {
        boolean is_success = cabinetTypeService.updateById(cabinetType);
        AjaxResult ajaxResult = toAjax(is_success);
        return ajaxResult;
    }


    /**
     * 新增
     *
     * @param cabinetType
     * @return
     */
    @Operation(summary = "新增")
    @PostMapping
    public AjaxResult add(@RequestBody  CabinetType cabinetType) {
        boolean is_success = cabinetTypeService.save(cabinetType);
        AjaxResult result = toAjax(is_success);
        return result;
    }

    /**
     * 根据ID查询详情
     *
     * @param id
     * @return
     */

    @Operation(summary = "根据ID查询详情")
    @GetMapping("/{id}")
    public AjaxResult getCabinetType(@PathVariable Long id) {
        CabinetType cabinetType = cabinetTypeService.getById(id);
        AjaxResult result = success(cabinetType);
        return result;
    }


    /**
     * 查询柜机类型表列表
     *
     * @param cabinetType
     * @return
     */
    @Operation(summary = "查询柜机类型表列表")
    @GetMapping("/list")
    public TableDataInfo list(CabinetType cabinetType) {
        // 分页查询
        startPage();
        List<CabinetType> list = cabinetTypeService.selectCabinetTypeList(cabinetType);
        logger.info("查询到{}条数据", list.size());
        return getDataTable(list);
    }
}
